package com.ruoyi.yn.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yn.vo.YnRecyclingWeightVo;
import com.ruoyi.yn.service.IYnRecyclingWeightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 回收重量Controller
 *
 * @author Ming
 * @date 2023-04-25
 */
@Api(tags = "回收重量Controller")
@RestController
@RequestMapping("/yn/recyclingWeight")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class YnRecyclingWeightController extends BaseController {

    private final IYnRecyclingWeightService ynRecyclingWeightService;

    @ApiOperation("查询回收重量列表")
    @PreAuthorize("@ss.hasPermi('yn:recyclingWeight:list')")
    @GetMapping("/list")
    public TableDataInfo<YnRecyclingWeightVo> list(YnRecyclingWeightVo entity) {
        return ynRecyclingWeightService.queryList(entity);
    }

    @ApiOperation("查询回收重量所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(YnRecyclingWeightVo entity) {
        return AjaxResult.success("查询成功", ynRecyclingWeightService.queryAll(entity));
    }

    @ApiOperation("导出回收重量列表")
    @PreAuthorize("@ss.hasPermi('yn:recyclingWeight:export')")
    @Log(title = "回收重量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YnRecyclingWeightVo entity) {
        List<YnRecyclingWeightVo> list = ynRecyclingWeightService.queryAll(entity);
        ExcelUtil<YnRecyclingWeightVo> util = new ExcelUtil<>(YnRecyclingWeightVo.class);
        util.exportExcel(response, list, "回收重量数据");
    }

    @ApiOperation("获取回收重量详细信息")
    @PreAuthorize("@ss.hasPermi('yn:recyclingWeight:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success("查询成功", ynRecyclingWeightService.queryById(id));
    }

    @ApiOperation("新增回收重量")
    @PreAuthorize("@ss.hasPermi('yn:recyclingWeight:add')")
    @Log(title = "回收重量", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody YnRecyclingWeightVo entity) {
        return toAjax(ynRecyclingWeightService.save(entity));
    }

    @ApiOperation("修改回收重量")
    @PreAuthorize("@ss.hasPermi('yn:recyclingWeight:edit')")
    @Log(title = "回收重量", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody YnRecyclingWeightVo entity) {
        return toAjax(ynRecyclingWeightService.updateById(entity));
    }

    @ApiOperation("删除回收重量")
    @PreAuthorize("@ss.hasPermi('yn:recyclingWeight:remove')")
    @Log(title = "回收重量", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(ynRecyclingWeightService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
